package cn.sue.example.three;

import android.content.Context;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

public class saveUser {
     public  static  boolean saveUserInfo(Context context, String number,String password){
         try {
             FileOutputStream fos = context.openFileOutput("data.txt", context.MODE_PRIVATE);
             fos.write((number+":"+password).getBytes());
             fos.close();
           return  true;
         } catch (Exception e) {
             e.printStackTrace();
             return  false;
         }
     }

     public  static  Map<String,String> getUserInfo (Context context){
         String  content="";
         try {
             FileInputStream fis = context.openFileInput("data.txt");
             byte[] buffer=new byte[fis.available()];
             fis.read(buffer);
             Map<String ,String> userId=new HashMap<String ,String>();
             content=new String(buffer);
             String[] info = content.split(":");

             userId.put("user",info[0]);
             userId.put("password",info[1]);

             fis.close();
             return userId;


         } catch (Exception e) {
             e.printStackTrace();
             return null;
         }

     }
}

